<?php

/**
* @copyright   (C) 2010 iJoomla, Inc. - All rights reserved.
* @license  GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html) 
* @author  iJoomla.com webmaster@ijoomla.com
* @url   http://www.ijoomla.com/licensing/
* the PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript  
* are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0 
* More info at http://www.ijoomla.com/licensing/
*/

defined('_JEXEC') or die('Restricted Access');
JHtml::_('behavior.tooltip');

include(JPATH_ROOT.DS."administrator".DS."components".DS."com_surveys".DS."left.php");
	
	$document =& JFactory::getDocument();
	$document->addStyleSheet(JURI::root()."components/com_surveys/css/survey.css");	
	$document->addScript(JURI::base()."components/com_surveys/javascript/survey_functions.js");

	$user =& JFactory::getUser();
	$user_id = $user->id;
	
	$survey_id_alias = JRequest::getVar("id", "0");
	$survey_id_array = explode(":", $survey_id_alias);
	$survey_id = $survey_id_array["0"];
	$current_page_id = JRequest::getVar("page", "0");
	$session_id = "";
	$show_survey = true;
	$params = $this->Params();

	
	$survey_details = $this->SurveyDetails($survey_id);
	$all_pages = $this->allPages($survey_id);

?>

<?php 	
	if($current_page_id == "0"){
		$current_page_id = isset($completed["page_to_view"]) ? intval($completed["page_to_view"]) : "0";
	}
	if($current_page_id == "last"){
		$show_survey = false;
	}
	$session_id = isset($completed["session_id"]) ? intval($completed["session_id"]) : "";
?>

	<?php
		if($show_survey != false){
	?>
			<!-- survey header, image and description -->
			<table cellspacing="0" cellpadding="0" align="center" class="<?php echo $params->survey_name; ?>">
				<tr>
					<td colspan="1" class="tableh1">
						<table width="100%" cellspacing="0" cellpadding="0" border="0">
							<tr>
								<td class="<?php echo $params->survey_name; ?>"><?php echo $survey_details["0"]["title"]; ?></td>
							</tr>
						</table>
				  </td>
				</tr>
				<?php if($survey_details["0"]["imagelist"] != ""){?>
				<tr>    	
					<td class="survey_image">
						<img border="0" alt="" src="images/sampledata/<?php echo $survey_details["0"]["imagelist"]; ?>" />
					</td>
					<td>			
						<span class="<?php echo $params->survey_description; ?>"><?php echo $survey_details["0"]["description"]; ?></span>
					</td>
				</tr>
				<?php }//if?>
			</table>	
		
			<!-- page title, image, description -->
			<?php
				if(count($all_pages)>0){			
					if($current_page_id == "0" || $current_page_id == "-1"){
						$current_page_id = $all_pages["0"]["id"];
					}										
					$page_details = $this->pageDetails($current_page_id);		
			?>
				<table>
					<?php 
						//if is set to display page title or no
						if($page_details["0"]["show_title"] == "1"){ 
					?>
					<tr class="<?php echo $params->page_name; ?>">
						<td><?php echo $page_details["0"]["title"]; ?></td>
					</tr>
					<?php 
						}
					?>
					<tr>
						<td class="page_image">
							<img alt="" src="images/sampledata/<?php echo $page_details["0"]["imagelist"]; ?>" />
						</td>
						<td>
							<span class="<?php echo $params->page_description; ?>"><?php echo $page_details["0"]["description"]; ?></span>
						</td>
					</tr>
				</table>
			<?php
				}
			}	
			?>		
	<?php
		$page_order = "0";
		if(isset($page_details) && isset($page_details["0"]["ordering"])){
			$page_order = $page_details["0"]["ordering"];
		}
		$pages = $this->getPrevNextPage($survey_id, $current_page_id, $page_order);		
		$prev_page = $pages["prev"];
		$next_page = $pages["next"];		
	?>


<form name="survey_content" id="survey_content" method="post" action="index.php?option=com_surveys&controller=prevsurvey&id=2&page=<?php echo $next_page; ?>">	
	<?php 			
		if($show_survey === true){							
			echo $this->surveyContent($survey_id, $current_page_id, $params, $session_id); 
		}
		
		if($current_page_id == "last"){
			echo $this->lastPage($survey_id, $params, $survey_id_alias);
		}
	?>		
	<input type="hidden" name="previews_page_id" value="<?php echo $prev_page; ?>" />
	<input type="hidden" name="current_page_id" value="<?php echo $current_page_id; ?>" />
	<input type="hidden" name="next_page_id" value="<?php echo $next_page; ?>" />
	<input type="hidden" name="task" value=""/>
	<input type="hidden" name="session_id" value="<?php echo $session_id; ?>" />
	<?php
		if($session_id != ""){
			$_SESSION["session_id"] = $session_id;
		}
	?>
	<input type="hidden" name="survey_id" value="<?php echo $survey_id; ?>" />
	<input type="hidden" name="survey_id_alias" value="<?php echo $survey_id_alias; ?>" />
	<input type="hidden" name="option" value="com_surveys"/>
	<input type="hidden" name="controller" value="prevsurvey"/>
</form>

</td></tr></table>
<p><center><?php echo JText::_("COM_IJOOMLA_SURVEYS_POWERED_BY") ; ?>&nbsp;<a href='http://www.ijoomla.com' target='_blank'><?php echo JText::_("COM_SURVEYS_SURVEY"); ?></a></center></p>	